<?php
namespace Message\Controller;
use Think\Controller;
class IndexController extends Controller {
    public function sendDayuSmsPlus($tel,$number)
    {

        $Send = new \Org\Net\SendTemplateSMS();
        $Send->sendTemplateSMS($tel,array($number,'5'),'1');


       /* $client = new \Message\Controller\TopClientController();
        $client->appkey = '23401196';
        $client->secretKey = '151585b2fa75d78ac918580b8df46151';
        $req = new \Message\Controller\AlibabaAliqinFcSmsNumSendRequestController();
// 设置请求参数
        $req ->setSmsTemplateCode('SMS_11750034');
        $req ->setRecNum($tel);
        $url = "{\"number\":\"" . $number. "\"}";
        $req->setSmsParam($url);
        $req ->setSmsFreeSignName('e护上门');
        $req ->setSmsType('normal');
        $req ->setExtend('demo');

        $client->execute($req);*/
     //  print_r($client->execute($req));
    }

    /**
     * 发送审核邮件
     * @param $email
     */
    public function sendReviewEmail($email,$token){
        //将该邮箱存入数据表  用于发送反馈信息
        M('user')->where(['token'=>$token])->setField(['email'=>$email]);
        $option = C('EMAIL_MSG');
        if(!sentEmail($email,$option['title'],$option['content'])){
            //如果邮箱发送失败  循环3次再次发送邮件
            for($i=0;$i<2;$i++){
                //如果成功了 就返回true
                if(sentEmail($email,$option['title'],$option['content'])){
                    $this->ajaxReturn(['status'=>1]);
                    exit;
                }
            }
            $this->ajaxReturn(['status'=>0]);
            exit;
        }
        $this->ajaxReturn(['status'=>1]);
    }

    /**
     * 发送推送消息
     * @param $pid 秘钥,md5(年月日时（如2016050511）.md5('ola'))
     * @param $content 消息内容
     * @param string $token 指定推送的用户token，为空指向所有在线用
     */
    public function sendPushMessage($pid,$content,$token=''){
        //验证秘钥：
        if($pid != md5(date('YmdH',time()).md5('ola'))){
//            echo json_encode(['status'=>'0']);
            exit;
        }
        // 指明给谁推送，为空表示向所有在线用户推送
        $to_uid = $token;
        // 推送的url地址，上线时改成自己的服务器地址
        $push_api_url = "http://api.chinaola.net:2121/";
        $post_data = array(
            "type" => "publish",
            "content" => $content,
            "to" => $to_uid,
        );
        $ch = curl_init ();
        curl_setopt ( $ch, CURLOPT_URL, $push_api_url );
        curl_setopt ( $ch, CURLOPT_POST, 1 );
        curl_setopt ( $ch, CURLOPT_HEADER, 0 );
        curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
        curl_setopt ( $ch, CURLOPT_POSTFIELDS, $post_data );
        curl_setopt ($ch, CURLOPT_HTTPHEADER, array("Expect:"));
        $return = curl_exec ( $ch );
        curl_close ( $ch );
//        echo json_encode(['status'=>$return]);
    }

    public function sendPushMessage1(){
        var_dump(md5(date('YmdH',time()).md5('ola')));exit;
    }

}